package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

func variableZeroValue() {
	var a int
	var s string
	fmt.Printf("%d %q\n", a, s) //百分号q会把空串的引号打出来
}
func variableInitialValue() {
	var a, b int = 3, 4
	var s string = "初始化"
	fmt.Println(a, b, s)
}

func variableTypeDeduction() {
	var a, b, c, d = 3, 4, true, "def"
	fmt.Println(a, b, c, d)
}
func variableShorter() {
	a, b, c, d := 3, 4, true, "def" // 第一次变量的方式
	fmt.Println(a, b, c, d)
}

func euler() {
	c := 3 + 4i
	fmt.Println(cmplx.Abs(c))
	// 验证欧拉公式
	fmt.Println(cmplx.Pow(math.E, 1i*math.Pi) + 1)
	fmt.Println(cmplx.Exp(1i*math.Pi) + 1)
	fmt.Printf("%.3f\n", cmplx.Exp(1i*math.Pi)+1)
}

func triangle() {
	var a, b int = 3, 4
	var c int
	c = int(math.Sqrt(float64(a*a + b*b)))
	fmt.Println(c)
}

func consts() {
	//const filename = "abc.txt"
	//const a, b = 3, 4
	const (
		filename = "abc.txt"
		a, b     = 3, 4
	)
	var c int
	c = int(math.Sqrt(float64(a*a + b*b)))
	fmt.Println(filename, c)
}

func enums() {
	//const (
	//	cpp    = 0
	//	java   = 1
	//	python = 2
	//	golang = 3
	//)
	// iota,表示为自增值
	const (
		cpp = iota
		java
		python
		golang
	)

	fmt.Println(cpp,
		java,
		python,
		golang)

	// b,kb,mb,gb,tb,pb
	const (
		b = 1 << (10 * iota) //左移10倍
		kb
		mb
		gb
		tb
		pb
	)
	fmt.Println(
		b,
		mb,
		gb,
		tb,
		pb)
}

func main() {
	//fmt.Println("hello world basic")
	//variableZeroValue()
	//variableInitialValue()
	//variableTypeDeduction()
	//variableShorter()
	//
	//euler()
	//triangle()
	//consts()
	enums()
}
